package com.yangguang.huahui.mvp.presenter;

import com.yangguang.huahui.entity.BuyEditInfo;
import com.yangguang.huahui.entity.HttpResult;
import com.yangguang.huahui.mvp.model.PurchaseModel;
import com.yangguang.huahui.mvp.view.PublishView;
import com.yangguang.huahui.rx.RxManager;
import com.yangguang.huahui.rx.RxSubscriber;

/**
 * Created by Administrator on 2017/3/21.
 */

public class PublishBuyPresenter extends BasePresenter<PublishView>{
    PurchaseModel model;

    public PublishBuyPresenter() {
        model = new PurchaseModel();
    }
    public void publish(String uid, String goods_type, String variety, String goods_title, String high_price,
                        String low_price, String demand, String source_id, String receipt_address, String deadline,
                        String contacts, String phone, String remark){
        mSubscription = RxManager.getInstance().doSubscribe(model.publish(uid, goods_type, variety, goods_title, high_price, low_price, demand, source_id, receipt_address,
                deadline, contacts, phone, remark), new RxSubscriber<HttpResult>(false) {
            @Override
            protected void _onNext(HttpResult httpResult) {
                mView.onSuccess(httpResult);
            }

            @Override
            protected void _onError() {
                mView.onError();
            }
        });
    }

    public void getEditData(String id){
        mSubscription = RxManager.getInstance().doSubscribe(model.getInfo(id), new RxSubscriber<BuyEditInfo>(false) {
            @Override
            protected void _onNext(BuyEditInfo buyEditInfo) {
                mView.onSuccess(buyEditInfo);
            }

            @Override
            protected void _onError() {
                mView.onError();
            }
        });
    }

    public void edit(String id, String paramKey, String paramValue){
        mSubscription = RxManager.getInstance().doSubscribe(model.edit(id, paramKey, paramValue), new RxSubscriber<HttpResult>(false) {
            @Override
            protected void _onNext(HttpResult httpResult) {
                mView.onSuccess(httpResult);
            }

            @Override
            protected void _onError() {
                mView.onError();
            }
        });
    }
}
